package com.atguigu.spzx.manner.controller;

import com.atguigu.spzx.manner.service.SysRoleMenuService;
import com.atguigu.spzx.model.dto.AssginRoleDto;
import com.atguigu.spzx.model.entity.AssignMenuDto;
import com.atguigu.spzx.model.entity.SysMenu;
import com.atguigu.spzx.model.myemun.ResultCodeEnum;
import com.atguigu.spzx.model.vo.common.Result;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping(value = "/admin/system/sysRoleMenu")
@RestController
@CrossOrigin(allowCredentials = "true", originPatterns = "*", allowedHeaders = "*")
public class SysRoleMenuController {
    @Autowired
    private SysRoleMenuService sysRoleMenuService;
    @GetMapping("/findSysRoleMenuByRoleId/{id}")
    public Result<Map<String, Object>> findSysRoleMenuByRoleId(@PathVariable("id") Long id) {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
       List <SysMenu> sysMenuList= sysRoleMenuService.findSysRoleMenu();
        List<Long> sysMenuList1 = sysRoleMenuService.findSysRoleMenuByRoleId(id);
        stringObjectHashMap.put("allMenuList",sysMenuList);
        stringObjectHashMap.put("sysMenuListById",sysMenuList1);
        return Result.build(stringObjectHashMap, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssignMenuDto assignMenuDto) {
        sysRoleMenuService.doAssign(assignMenuDto);
        return Result.build(ResultCodeEnum.SUCCESS);
    }
}
